`
https://leetcode.cn/problems/count-good-nodes-in-binary-tree/
`

/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {number}
 */
var goodNodes = function (root) {
  let count = 0

  const traverse = (root, pathMax) => {
    if (root === null) return

    // 当前值大于等于路径上的最高值
    if (root.val >= pathMax) {
      count++
    }

    pathMax = Math.max(pathMax, root.val)

    traverse(root.left, pathMax)
    traverse(root.right, pathMax)
  }

  traverse(root, root.val)

  return count
};